.jumbotron
  h2 API version 2
  small Path prefix: /api/v2
  br
  small Response format: JSON

.panel.panel-default
  .panel-heading
    h3 Public/Private API

  .panel-body
    p Peatio API v2 includes both public API and private API.

  table.table
    thead
      tr
        th Public API
        th Private API
    tbody
      tr
        td No authentication required
        td Authentication required
      tr
        td Unlimited
        td 6000 requests/keypair/5minutes, you can contact Peatio if you need more.
      tr
        td Ready to use
        td You need to request for access/secret key at first

.panel.panel-default
  .panel-heading
    h3 Authentication

  .panel-body
    p To use private API, you need to get your access/secret key first. After signed up and verified, please visit <a href='/api_tokens'>API Tokens page</a> to get your keys.
    p All private API requires 3 authentication parameters and zero or more API specific parameters. The 3 authentication parameters are:
    table.table
      tr
        td access_key
        td Your access key.
      tr
        td tonce
        td tonce is a timestamp in integer, stands for milliseconds elapsed since <a href='http://en.wikipedia.org/wiki/Unix_epoch'>Unix epoch</a>. Tonce must be within 30 seconds of server's current time. Each tonce can only be used once.
      tr
        td signature
        td Signature of the API request, generated by you, use your secret key.

    p Signature is a hash of the request (in canonical string form):
    pre: code
      | hash = HMAC-SHA256(payload, secret_key).to_hex

    p Payload is a combination of HTTP verb, uri, and query string:
    pre: code
      | # canonical_verb is HTTP verb like GET/POST in upcase.
        # canonical_uri is request path like /api/v2/markets.
        # canonical_query is the request query sorted in alphabetica order, including access_key and tonce, e.g. access_key=xxx&foo=bar&tonce=123456789
        # The combined string looks like: GET|/api/v2/markets|access_key=xxx&foo=bar&tonce=123456789
        def payload
          "\#{canonical_verb}|\#{canonical_uri}|\#{canonical_query}"
        end

    p Note: query parameters are sorted in payload, so it must be "access_key=xxx&foo=bar" not "foo=bar&&access_key=xxx".
    p Suppose my secret key is 'yyy', then the result of HMAC-SHA256 of above payload is:
    pre: code
      | hash = HMAC-SHA256('GET|/api/v2/markets|access_key=xxx&foo=bar&tonce=123456789', 'yyy').to_hex
             = 'e324059be4491ed8e528aa7b8735af1e96547fbec96db962d51feb7bf1b64dee'

    p Now we hav a signed request which can be used like this:
    pre: code
      | curl -X GET 'https://peatio.com/api/v2/markets?access_key=xxx&foo=bar&tonce=123456789&signature=e324059be4491ed8e528aa7b8735af1e96547fbec96db962d51feb7bf1b64dee'

.panel.panel-default
  .panel-heading
    h3 Response Format

  .panel-body
    p Corresponding HTTP status code will be used in API response. Peatio will also return a JSON structure including error details on failed request, for example:
    pre: code
      | {"error":{"code":1001,"message":"market does not have a valid value"}}
    p All errors follow the message format above, only differentiates in code and message. Code is a Peatio defined error code, indicates the error's category, message is human-readable details.

  .panel-body
    p Peatio returns HTTP 200 response on successful request, with requested data in JSON format.
    table.table.result
      thead
        tr
          th Data Type
          th Example
          th Comments
      tbody
        tr
          td Market
          td: pre: code
            | {"at":1398410899, "ticker":{"buy":"3000.0","sell":"3100.0","low":"3000.0","high":"3000.0","last":"3000.0","vol":"0.11"}}
          td
            p at: A timestamp in seconds since Epoch
            p buy/sell: Current buy/sell price
            p low/high: Lowest/highest price in last 24 hours
            p last: Last price
            p vol: Trade volume in last 24 hours
        tr
          td Member
          td: pre: code
            | {"sn":"PEA5TFFOGQHTIO","name":"foo","email":"foo@peatio.dev","activated":true,"accounts":[{"currency":"cny","balance":"100243840.0","locked":"0.0"},{"currency":"btc","balance":"99999708.26","locked":"210.8"}]}
          td
            p sn: Unique identifier of user
            p name: User name
            p email: User email
            p activated: Whether user is activated
            p accounts: User's accounts info, see Account
        tr
          td Account
          td: pre: code
            | {"currency":"cny","balance":"100243840.0","locked":"0.0"}
          td
            p currency: Account type, like 'btc' or 'cny'
            p balance: Account balance, exclude locked funds
            p locked: locked funds
        tr
          td Order
          td: pre: code
            | {"id":7,"side":"sell","price":"3100.0","avg_price":"3101.2","state":"wait","market":"btccny","created_at":"2014-04-18T02:02:33Z","volume":"100.0","remaining_volume":"89.8","executed_volume":"10.2","trades":[{"id":2,"price":"3100.0","volume":"10.2","market":"btccny","created_at":"2014-04-18T02:04:49Z","side":"sell"}]}
          td
            p id: Unique order ID
            p side: Buy/Sell
            p price: Order price
            p avg_price: Average execution price
            p state: wait, done or cancel. 'wait' represents the order is active, it may be a new order or partial complete order; 'done' means the order has been fulfilled completely; 'cancel' means the order has been cancelled.
            p market: Which market the order belongs to
            p created_at: Order created time
            p volume: volume to buy/sell
            p remaining_volume: remaining_volume is always less or equal than volume
            p executed_volume: volume = remaining_volume + executed_volume
            p trades: the order's trade history, see Trade. Note: not all order include trades, only detailed order data returned by certain API will.
        tr
          td Trade
          td: pre: code
            | {"id":2,"price":"3100.0","volume":"10.2","market":"btccny","created_at":"2014-04-18T02:04:49Z","side":"sell"}
          td
            p id: Unique ID
            p price: trade price
            p volume: trade volume
            p market: the market trade belongs to, like 'btccny'
            p created_at: trade time
        tr
          td OrderBook
          td: pre: code
            | {"asks": [...],"bids": [...]}
          td
            p OrderBook shows orders on market.

.panel.panel-default
  .panel-heading
    h3 Some Examples

  .panel-body
    p Buy 1BTC at price 4000CNY:
    pre: code
      | curl -X POST 'https://peatio.com/api/v2/orders' -d 'access_key=your_access_key&tonce=1234567&signature=computed_signature&market=btccny&price=4000&side=buy&volume=1'

    p Create multiple orders with a single request:
    pre: code
      | curl -X POST 'https://peatio.com/api/v2/orders/multi' -d 'access_key=your_access_key&tonce=123456789&signature=computed_signature&market=btccny&orders[][price]=4000&orders[][side]=sell&orders[][volume]=0.5&orders[][price]=3999&orders[][side]=sell&orders[][volume]=0.99'

.panel.panel-default
  .panel-heading
    h3 Tips/Caveats

  .panel-body
    table.table
      thead
        tr
          th API
          th Detail
      tbody
        tr
          td POST /api/v2/order/delete
          td Cancel order is an asynchronous operation. A success response only means your cancel request has been accepted, it doesn't mean the order has been cancelled. You should always use /api/v2/order or websocket api to get order's latest state.
        tr
          td POST /api/v2/orders/clear
          td Cancel all your orders is an asynchronous operation. A success response only means your request has been accepted. The orders in response may or may not have been cancelled yet.

.panel.panel-default
  .panel-heading
    h3 Libraries/Tools

  .panel-body
    ul
      li: h4
        a href='http://github.com/peatio/peatio-client-ruby'
          | peatio-client-ruby (ruby)

.panel.panel-default
  .panel-heading
    h3 API List

  .panel-body
    p All API are listed below with details. Those require access_key/tonce/signature are private API.

.row
  #swagger-ui-container.swagger-ui-wrap
